package com.sztx.pay.center.worker;

import java.util.HashMap;
import java.util.Map;

import org.quartz.JobExecutionContext;
import org.springframework.beans.factory.annotation.Autowired;

import com.sztx.pay.center.worker.quartz.ScanSettleLaterOrderJob;
import com.sztx.se.core.quartz.component.QuartzManager;

public class WorkInitJob {
	private String notifyCron;
	private String settleCron;
	private String withdrawCron;
	
	
	@Autowired
	private QuartzManager quartzManager;

	//	@Autowired(required = false)
//	private ScheduleManager scheduleManager;
	public void init(){
		settleJobInit();
		notifyJobInit();
		withdrawJobInit();
	}
	
	private void settleJobInit(){
		String schedName = "tradeCenterScheduler";
		String jobName = "扫描定时结算订单任务";
		String jobGroup = "结算订单任务组";
		String jobClassName = "scanSettleLaterOrderJob";
		String description = "扫描未结算的定时结算订单并进行结算";
		boolean isRecovery = false;
		String triggerName = "每两分钟执行的结算扫描";
		String triggerGroup = "结算扫描触发器组";
		boolean isCronTrigger = true;
		//String expression = "0 */2 * * * ?";
		String expression = this.settleCron;
		Map<String, String> extraInfo = new HashMap<String, String>();
		extraInfo.put("extra", "demo");
		quartzManager.saveOrUpdateJob(schedName, jobName, jobGroup, jobClassName, description, isRecovery, triggerName, triggerGroup, isCronTrigger,
				expression, null, null, extraInfo);
	}
	
	private void notifyJobInit(){
		String schedName = "tradeCenterScheduler";
		String jobName = "订单业务回调任务";
		String jobGroup = "订单业务回调任务组";
		String jobClassName = "notifyJob";
		String description = "扫描未回调的业务订单进行回调";
		boolean isRecovery = false;
		String triggerName = "每分钟执行的业务回调";
		String triggerGroup = "业务回调触发器组";
		boolean isCronTrigger = true;
		//String expression = "0 */1 * * * ?";
		String expression = this.notifyCron;
		Map<String, String> extraInfo = new HashMap<String, String>();
		extraInfo.put("extra", "demo");
		quartzManager.saveOrUpdateJob(schedName, jobName, jobGroup, jobClassName, description, isRecovery, triggerName, triggerGroup, isCronTrigger,expression, null, null, extraInfo);
	}
	
	private void withdrawJobInit(){
		String schedName = "tradeCenterScheduler";
		String jobName = "定时提现任务";
		String jobGroup = "定时提现任务组";
		String jobClassName = "withdrawJob";
		String description = "扫描达到条件的提现订单进行提现";
		boolean isRecovery = false;
		String triggerName = "每天12点24点进行两次扫描";
		String triggerGroup = "定时提现触发器组";
		boolean isCronTrigger = true;
		//String expression = "0 0 0,12 * * ?";
		String expression = this.withdrawCron;
		Map<String, String> extraInfo = new HashMap<String, String>();
		extraInfo.put("extra", "demo");
		quartzManager.saveOrUpdateJob(schedName, jobName, jobGroup, jobClassName, description, isRecovery, triggerName, triggerGroup, isCronTrigger,expression, null, null, extraInfo);
	}

	public String getNotifyCron() {
		return notifyCron;
	}

	public void setNotifyCron(String notifyCron) {
		this.notifyCron = notifyCron;
	}

	public String getSettleCron() {
		return settleCron;
	}

	public void setSettleCron(String settleCron) {
		this.settleCron = settleCron;
	}

	public String getWithdrawCron() {
		return withdrawCron;
	}

	public void setWithdrawCron(String withdrawCron) {
		this.withdrawCron = withdrawCron;
	}
	
}
